package Fan;

import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Arc;
import javafx.scene.shape.ArcType;
import javafx.scene.shape.Circle;

public class FanAchieve extends Pane {


    //12个扇形
    private Arc arc[] = new Arc[12];
    //设置三个扇形的初始角度
    private double startAngle1 = 30;
    private double startAngle2 = 30;
    private double startAngle3 = 30;
    //风扇转动是每次增长的度数
    private double increment = 5;
    //3个圆
    private Circle[] circles = new Circle[3];
    public FanAchieve(){
        for(int i = 200,j=0; i<=1200; i+=400,j++){
            //设定3个圆的圆心
            circles[j] = new Circle();
            circles[j].setCenterX(i);
            circles[j].setCenterY(400/2);
            circles[j].setRadius(140);
            //边缘
            circles[j].setStroke(Color.BLUE);
            //填充颜色
            circles[j].setFill(Color.WHITE);
            //添加到面板中
            getChildren().add(circles[j]);
        }


        //为每个圆创建风扇
        for(int m = 0; m<12; m++){
            arc[m] = new Arc();
            //一个圆中有四个扇形并绑定圆心
            arc[m].centerXProperty().bind(circles[m/4].centerXProperty());
            arc[m].centerYProperty().bind(circles[m/4].centerYProperty());
            //扇形半径略小于圆
            arc[m].radiusXProperty().bind(circles[m/4].radiusProperty().divide(1.05));
            arc[m].radiusYProperty().bind(circles[m/4].radiusProperty().divide(1.05));
            //圆弧起始位置
            arc[m].setStartAngle(30+m*90);
            //圆弧长度
            arc[m].setLength(60);
            arc[m].setFill(Color.BLACK);
            arc[m].setType(ArcType.ROUND);
            getChildren().addAll(arc[m]);
        }
    }

    //public void reverse(){}

    //第一个风扇旋转方法
    public void move1(){
        setStartAngle1(startAngle1 + increment);
    }

    //设置角度
    public void setStartAngle1(double angle){
        startAngle1 = angle;
        setValues1();
    }

    //第二个风扇旋转方法
    public void move2(){
        setStartAngle2(startAngle2 + increment);
    }

    public void setStartAngle2(double angle){
        startAngle2 = angle;
        setValues2();
    }

    //第三个风扇旋转方法
    public void move3(){
        setStartAngle3(startAngle3 + increment);
    }

    public void setStartAngle3(double angle){
        startAngle3 = angle;
        setValues3();
    }

    //控制3个风扇旋转的方法
    public void move(){
        setStartAngle(increment);
    }

    public void setStartAngle(double angle){
        startAngle1 += angle;
        startAngle2 += angle;
        startAngle3 += angle;
        setValues1();
        setValues2();
        setValues3();
    }

    /*public void setValues(){
        for(int i = 0; i<12; i++){
            arc[i].setStartAngle(startAngle + i*90);
        }
    }
*/

    public void setValues1(){
        for(int i = 0; i<4; i++){
            arc[i].setStartAngle(startAngle1 + i*90);
        }
    }
    public void setValues2(){
        for(int i = 4; i<8; i++){
            arc[i].setStartAngle(startAngle2 + (i-4)*90);
        }
    }

    public void setValues3(){
        for(int i = 8; i<12; i++){
            arc[i].setStartAngle(startAngle3 + (i-8)*90);
        }
    }
}
